#include "debug.h"
#include "Utils\\Font.h"
#include "Utils\\Color.h"
#include "Utils\\ResGroupManager.h"
#include "Elements\\AButton.h"

using namespace SDL::UTILS;

NS_BEGIN(SDL)
NS_BEGIN(ELEMENTS)

#pragma region CTOR & DTOR

AButton::AButton(std::wstring const& _text) : AElement(),
m_state(BUTTON::STATE::RELEASED),
m_imgReleased(NULL), m_imgHovered(NULL), m_imgPressed(NULL),
m_imgClicked(NULL), m_imgDisabled(NULL),
m_text(new Font("C:\\Windows\\Fonts\\arial.ttf", 16), Color(), true),
m_resGroup(NULL)
{
	CTOR("AButton", this);
	m_text.Render(_text);
	m_resGroup = ResGroupManager::Instance()[ResGroupManager::DEFAULT_GROUP];
}

AButton::AButton(AButton const& _abutton) : AElement(*((AElement*)&_abutton)),
m_text(NULL, Color())
{
	CTOR("AButton", this);
	*this = _abutton;
}

AButton::~AButton()
{
	DTOR("AButton", this);
}

#pragma endregion
#pragma region Operators

AButton& AButton::operator=(AButton const& _abutton)
{
	if (this != &_abutton)
	{
		*((AElement*)this) = *((AElement*)&_abutton);
		m_state = _abutton.m_state;
		m_imgReleased = _abutton.m_imgReleased;
		m_imgHovered = _abutton.m_imgHovered;
		m_imgPressed = _abutton.m_imgPressed;
		m_imgDisabled = _abutton.m_imgDisabled;
		m_text = _abutton.m_text;
	}
	return (*this);
}

bool AButton::operator==(AButton const& _abutton) const
{
	return (*((AElement*)this) == *((AElement*)&_abutton) &&
			m_state == _abutton.m_state &&
			m_imgReleased == _abutton.m_imgReleased &&
			m_imgHovered == _abutton.m_imgHovered &&
			m_imgPressed == _abutton.m_imgPressed &&
			m_imgDisabled == _abutton.m_imgDisabled &&
			m_text == _abutton.m_text);
}

bool AButton::operator!=(AButton const& _abutton) const
{
	return (!(*this == _abutton));
}

#pragma endregion
#pragma region Getters & Setters

BUTTON::STATE AButton::GetState() const
{
	return (m_state);
}

void AButton::SetState(BUTTON::STATE _state)
{
	m_state = _state;
	switch (m_state)
	{
	case BUTTON::STATE::RELEASED:
		m_surface = m_imgReleased;
		break ;
	case BUTTON::STATE::HOVERED:
		m_surface = m_imgHovered;
		break ;
	case BUTTON::STATE::PRESSED:
		m_surface = m_imgPressed;
		break ;
	case BUTTON::STATE::CLICKED:
		m_surface = m_imgClicked;
		break ;
	default:
		m_surface = NULL;
		break ;
	}
}

std::wstring const& AButton::GetText() const
{
	return (m_text.GetText());
}

Label const& AButton::GetLabel() const
{
	return (m_text);
}

Font* AButton::GetFont() const
{
	return (m_text.GetFont());
}

void AButton::SetFont(Font* _font)
{
	m_text.SetFont(_font);
	m_text.SetDeleteFont(false);
	m_text.Render(m_text.GetText(), Font::RenderBlended);
	this->SetText(m_text.GetText());
}

ResGroup* AButton::GetResGroup() const
{
	return (m_resGroup);
}

void AButton::SetResGroup(ResGroup* _resGroup)
{
	m_resGroup = _resGroup;
}

#pragma endregion

NS_END(ELEMENTS)
NS_END(SDL)
